package com.eyedog.video.db2.tables;

import android.content.ContentValues;
import android.database.Cursor;

import com.eyedog.video.db2.entities.ContactsVerEntity;

/**
 * 描述：
 *
 * @author walljiang
 * @since 2017/08/30 15:06
 */

public class ContactsVerTable extends BaseTable<ContactsVerEntity> {

    public static final String TABLE_NAME = "t_contactsver";

    public static final String VERSION = "version";

    public static final String MASTERID = "masterId";

    private static ContactsVerTable instance;

    public static ContactsVerTable getInstance(){
        if(instance == null){
            instance = new ContactsVerTable();
        }
        return instance;
    }

    @Override
    void addColumns() {
        addColumnInteger(VERSION);
        addColumnText(MASTERID);
    }

    @Override
    String getTableName() {
        return TABLE_NAME;
    }

    @Override
    ContentValues getCVFromEntity(ContactsVerEntity contactsVerTable) {
        if(contactsVerTable != null){
            ContentValues contentValues = new ContentValues();
            contentValues.put(VERSION,contactsVerTable.getVersion());
            contentValues.put(MASTERID,contactsVerTable.getMasterId());
            return contentValues;
        }
        return null;
    }

    @Override
    ContactsVerEntity getEntityFromCursor(Cursor cursor) {
        ContactsVerEntity entity = null;
        if(cursor != null && !cursor.isClosed()){
            entity = new ContactsVerEntity();
            entity.setVersion(cursor.getInt(cursor.getColumnIndex(VERSION)));
            entity.setMasterId(Long.parseLong(cursor.getString(cursor.getColumnIndex(MASTERID))));
        }
        return entity;
    }

}
